home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / multiuser / circus2 / scripts / cannon.class (.txt) next >
Encoding:
Java Class File  |  1996-09-20  |  4.4 KB  |  202 lines

  1. import vrml.Event;
  2. import vrml.field.ConstSFBool;
  3. import vrml.field.ConstSFString;
  4. import vrml.field.ConstSFTime;
  5. import vrml.field.SFBool;
  6. import vrml.field.SFNode;
  7. import vrml.field.SFRotation;
  8. import vrml.field.SFTime;
  9. import vrml.field.SFVec3f;
  10. import vrml.node.Script;
  11. import vs.Vscp;
  12.  
  13. public class cannon extends Script {
  14.    static int EVENT_VOID;
  15.    static int EVENT_BOOL = 1;
  16.    static int EVENT_TIME = 2;
  17.    // $FF: renamed from: X int
  18.    static int field_0;
  19.    // $FF: renamed from: Y int
  20.    static int field_1 = 1;
  21.    // $FF: renamed from: Z int
  22.    static int field_2 = 2;
  23.    static int DEGREE = 3;
  24.    float Radian = (180F / (float)Math.PI);
  25.    SFNode CannonNode;
  26.    SFBool CannonSwitch;
  27.    SFVec3f RocketmanPosition;
  28.    SFRotation RocketmanRotation;
  29.    SFTime CannonTrueSound_stop;
  30.    SFTime CannonTrueSound_start;
  31.    SFTime CannonFalseSound_stop;
  32.    SFTime CannonFalseSound_start;
  33.    SFTime CannonStartSound_stop;
  34.    SFTime CannonStartSound_start;
  35.    int CannonSwitchFlg;
  36.    int CannonMoveCnt = -1;
  37.    float BulletAng;
  38.    float BulletOrgY;
  39.    float BulletOrgZ = -80.0F;
  40.    float BulletAccel;
  41.    float BulletY;
  42.    float BulletZ;
  43.  
  44.    public void initialize() {
  45.       this.CannonNode = (SFNode)((Script)this).getField("CannonNode");
  46.       this.CannonSwitch = (SFBool)((Script)this).getEventOut("CannonTimer_enabled");
  47.       this.RocketmanPosition = (SFVec3f)((Script)this).getEventOut("CannonRocketman_position");
  48.       this.RocketmanRotation = (SFRotation)((Script)this).getEventOut("CannonRocketman_rotation");
  49.       this.CannonTrueSound_stop = (SFTime)((Script)this).getEventOut("CannonTrueSound_stop");
  50.       this.CannonTrueSound_start = (SFTime)((Script)this).getEventOut("CannonTrueSound_start");
  51.       this.CannonFalseSound_stop = (SFTime)((Script)this).getEventOut("CannonFalseSound_stop");
  52.       this.CannonFalseSound_start = (SFTime)((Script)this).getEventOut("CannonFalseSound_start");
  53.       this.CannonStartSound_stop = (SFTime)((Script)this).getEventOut("CannonStartSound_stop");
  54.       this.CannonStartSound_start = (SFTime)((Script)this).getEventOut("CannonStartSound_start");
  55.    }
  56.  
  57.    public void processEvent(Event var1) {
  58.       String var2 = var1.getName();
  59.       double var3 = var1.getTimeStamp();
  60.       if (var2.equals("CannonSw1Click")) {
  61.          this.CannonSw1Click((ConstSFBool)var1.getValue(), var3);
  62.       } else if (var2.equals("CannonSw2Click")) {
  63.          this.CannonSw2Click((ConstSFBool)var1.getValue(), var3);
  64.       } else if (var2.equals("CannonSw3Click")) {
  65.          this.CannonSw3Click((ConstSFBool)var1.getValue(), var3);
  66.       } else if (var2.equals("CannonMove")) {
  67.          this.CannonMove((ConstSFTime)var1.getValue(), var3);
  68.       } else {
  69.          if (var2.equals("CannonStartShare")) {
  70.             this.CannonStartShare((ConstSFString)var1.getValue(), var3);
  71.          }
  72.  
  73.       }
  74.    }
  75.  
  76.    void cannon_init() {
  77.       float[] var1 = new float[3];
  78.       var1[field_0] = 0.0F;
  79.       var1[field_1] = this.BulletOrgY;
  80.       var1[field_2] = this.BulletOrgZ;
  81.       this.RocketmanPosition.setValue(var1);
  82.    }
  83.  
  84.    public void soundSwitch(double var1, boolean var3, boolean var4) {
  85.       double var7 = var1 + (double)5.0F;
  86.       if (var3) {
  87.          if (var4) {
  88.             this.CannonTrueSound_start.setValue(var1);
  89.             this.CannonTrueSound_stop.setValue(var7);
  90.          } else {
  91.             this.CannonFalseSound_start.setValue(var1);
  92.             this.CannonFalseSound_stop.setValue(var7);
  93.          }
  94.       } else if (var4) {
  95.          this.CannonTrueSound_stop.setValue(var1);
  96.       } else {
  97.          this.CannonFalseSound_stop.setValue(var1);
  98.       }
  99.    }
  100.  
  101.    public void CannonSw1Click(ConstSFBool var1, double var2) {
  102.       this.CannonSwitchChk(var1, var2, 1);
  103.    }
  104.  
  105.    public void CannonSw2Click(ConstSFBool var1, double var2) {
  106.       this.CannonSwitchChk(var1, var2, 2);
  107.    }
  108.  
  109.    public void CannonSw3Click(ConstSFBool var1, double var2) {
  110.       this.CannonSwitchChk(var1, var2, 3);
  111.    }
  112.  
  113.    public void CannonSwitchChk(ConstSFBool var1, double var2, int var4) {
  114.       if (!var1.getValue()) {
  115.          if (this.CannonSwitchFlg < 4) {
  116.             if (var4 != this.CannonSwitchFlg) {
  117.                int var5 = var4 - this.CannonSwitchFlg;
  118.                if (var5 == 1) {
  119.                   ++this.CannonSwitchFlg;
  120.                   this.soundSwitch(var2, true, true);
  121.                   if (this.CannonSwitchFlg == 3) {
  122.                      this.CannonStart(var2);
  123.                      Vscp.sendApplSpecificMsgWithDist(this.CannonNode, "CannonStartShare", "dummy", 4);
  124.                      return;
  125.                   }
  126.                } else {
  127.                   this.CannonSwitchFlg = 0;
  128.                   this.soundSwitch(var2, true, false);
  129.                }
  130.  
  131.             }
  132.          }
  133.       }
  134.    }
  135.  
  136.    public void CannonStartShare(ConstSFString var1, double var2) {
  137.       this.CannonStart(var2);
  138.    }
  139.  
  140.    public void CannonStart(double var1) {
  141.       this.CannonSwitchFlg = 4;
  142.       this.CannonStartSound_start.setValue(var1);
  143.       double var3 = var1 + (double)10.0F;
  144.       this.CannonStartSound_stop.setValue(var3);
  145.       this.CannonMoveCnt = 0;
  146.       this.BulletAng = 45.0F;
  147.       this.BulletY = this.BulletOrgY;
  148.       this.BulletZ = this.BulletOrgZ;
  149.       this.BulletAccel = 5.0F;
  150.       this.CannonSwitch.setValue(true);
  151.    }
  152.  
  153.    public void CannonMove(ConstSFTime var1, double var2) {
  154.       float[] var4 = new float[3];
  155.       float[] var5 = new float[4];
  156.       float var6 = 3.0F;
  157.       float var8 = 5.0F;
  158.       float var7 = var8 / 15.0F;
  159.       if (this.CannonMoveCnt < 0) {
  160.          this.CannonSwitch.setValue(false);
  161.          this.cannon_init();
  162.       } else if (this.CannonMoveCnt < 30) {
  163.          var5[field_0] = 1.0F;
  164.          var5[field_1] = 0.0F;
  165.          var5[field_2] = 0.0F;
  166.          var5[DEGREE] = this.BulletAng / this.Radian;
  167.          this.RocketmanRotation.setValue(var5);
  168.          this.BulletAng += var6;
  169.          var4[field_0] = 0.0F;
  170.          var4[field_1] = this.BulletY;
  171.          var4[field_2] = this.BulletZ + 10.0F;
  172.          this.RocketmanPosition.setValue(var4);
  173.          this.BulletZ += var8;
  174.          this.BulletY += this.BulletAccel;
  175.          this.BulletAccel -= var7;
  176.       } else if (this.CannonMoveCnt == 30) {
  177.          var5[field_0] = 1.0F;
  178.          var5[field_1] = 1.0F;
  179.          var5[field_2] = 1.0F;
  180.          var5[DEGREE] = 0.0F;
  181.          this.RocketmanRotation.setValue(var5);
  182.          this.BulletY = this.BulletOrgY;
  183.       } else if (this.CannonMoveCnt < 60) {
  184.          var4[field_0] = 0.0F;
  185.          var4[field_1] = this.BulletY;
  186.          var4[field_2] = this.BulletZ;
  187.          this.RocketmanPosition.setValue(var4);
  188.          this.BulletZ -= var8;
  189.       } else if (this.CannonMoveCnt == 60) {
  190.          this.BulletZ = this.BulletOrgZ;
  191.          var4[field_0] = 0.0F;
  192.          var4[field_1] = this.BulletY;
  193.          var4[field_2] = this.BulletZ;
  194.          this.RocketmanPosition.setValue(var4);
  195.          this.CannonSwitchFlg = 0;
  196.          this.CannonSwitch.setValue(false);
  197.       }
  198.  
  199.       ++this.CannonMoveCnt;
  200.    }
  201. }
  202.